package com.musiklegal;



import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class InformationParser extends DefaultHandler
{
	boolean in_reply=false,
			in_status= false,
			in_username= false,
			in_password = false,
			in_description =false;
	
	ParsedLoginDataSet data;
	StringBuffer sb;
	InformationParser()
	{
		sb = new StringBuffer();
	}
	
	public void startDocument()
	{
		data = new ParsedLoginDataSet();
	}
	
	public void endDocument()
	{
		
	}
	
	public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException 
	{
		if(localName.compareToIgnoreCase("reply")==0)
			in_reply=true;
		if(in_reply)
		{
			if(localName.compareToIgnoreCase("status")==0)
				in_status =true;
			if(localName.compareToIgnoreCase("description")==0)
				in_description=true;
			if(localName.compareToIgnoreCase("username")==0)
				in_username =true;
			if(localName.compareToIgnoreCase("password")==0)
				in_password=true;
		}
	}
	
	 public void endElement(String namespaceURI, String localName, String qName) throws SAXException 
	 {
		 if (localName.equals("reply"))
         { in_reply= false;}
         else if (localName.equals("description"))
               {
        	 	in_description = false;
        	 	data.setExtractedString(sb.toString());
        	 	sb = new StringBuffer();
               }
         else if (localName.equals("status"))
        	 	{
        	 	in_status= false;
        	 	data.setStatus(sb.toString());
        	 	sb = new StringBuffer();
        	 	}
         else if (localName.equals("username"))
        	 	{
        	 	
        	 	in_username= false;
        	 	data.setUse(sb.toString());
        	 	sb = new StringBuffer();
        	 	}
         else if (localName.equals("password"))
             {
        	 	in_password =false;
        	 	data.setPas(sb.toString());
        	 	sb = new StringBuffer();
             }
	 }
	 
	 public void characters(char ch[], int start, int length) 
	 {
		 if(in_status)
				sb.append(new String(ch,start,length));
		 if(in_description)
			 sb.append(new String(ch,start,length));
		 if(in_username)
			 sb.append(new String(ch,start,length));
		 if(in_password)
			 sb.append(new String(ch,start,length));
	 }
	
	
}
